# ECON 331  97/1
# ASSIGNMENT #10
# 
# QUESTION 1
# 
> restart;
# Euler's Theorem:
# 
> Q:=f[k]*k +f[l]*l;
# 
# Profit function:
# 
> pi:=p*Q-r*k-w*l;

                         Q := f[k] k + f[l] l


                pi := p (f[k] k + f[l] l) - r k - w l

# First-order conditions:
# 
> sols:=solve({diff(pi,k),diff(pi,l)},{f[k],f[l]});

                   sols := {f[k] = r/p, f[l] = w/p}

# Substitute back into the profit function to show that maximum long-run
# profit is zero:
# 
> assign(sols);
> pi:=simplify(pi);
# 

                               pi := 0

# 
# 
# QUESTION 2
# 
# 
> restart;
# 
# Set up model:
# 
> p[1]:=22-10^(-5)*q[1]:
> p[2]:=18-10^(-5)*q[2]:
> Q:=q[1]+q[2]:
> L:=p[1]*q[1]+p[2]*q[2]-8*k-6*Q+lambda*(k-q[1])+mu*(k-q[2]);

L := (22 - 1/100000 q[1]) q[1] + (18 - 1/100000 q[2]) q[2] - 8 k

     - 6 q[1] - 6 q[2] + lambda (k - q[1]) + mu (k - q[2])

# a)
# 
# The Kuhn Tucker conditions are:
# 
#    L[1]<=0,  q[1]>=0,  L[1]*q[1]=0
#    L[2]<=0,  q[2] >=0,  L[2]*q[2]=0
#    L[k]<=0,  k>=0,  L[k]*k=0
#    L[lambda]>=0,  lambda>=0,  L[lambda]*lambda=0
#    L[mu]>=0,  mu>=0, L[mu]*mu=0
#      
# b)     
# 
# In general, it is best to proceed  by checking whether the conditions
# for an interior solution are satisfied before proceeding to check for
# corner solutions.  
# 
# The interior solution conditons are:
# 
#    L[1]=0, q1>0
#    L[2]=0, q[2]>0
#    L[k]=0,k>0
#    lambda>0, q[1]=k 
#     mu>0, q[2]=k
# 
# Note that the last two conditions imply q[1]=q[2].  Imposing these
# conditions and solving for q[1], q[2], k,lambda, mu:
# 
> with(linalg):
> a:=jacobian([diff(L,q[1]),diff(L,q[2]),diff(L,k),q[1]-q[2]],[q[1],q[2]
> ,lambda,mu]);
# 
Warning, new definition for norm
Warning, new definition for trace

                       [ -1                       ]
                       [-----      0      -1     0]
                       [50000                     ]
                       [                          ]
                       [          -1              ]
                  a := [  0      -----     0    -1]
                       [         50000            ]
                       [                          ]
                       [  0        0       1     1]
                       [                          ]
                       [  1       -1       0     0]

> b:=matrix(4,1,[-16,-12,8,0]);

                                   [-16]
                                   [   ]
                                   [-12]
                              b := [   ]
                                   [  8]
                                   [   ]
                                   [  0]

> matrix(4,1,[q[1],q[2],lambda,mu])=linsolve(a,b);

                         [ q[1] ]   [500000]
                         [      ]   [      ]
                         [ q[2] ]   [500000]
                         [      ] = [      ]
                         [lambda]   [     6]
                         [      ]   [      ]
                         [  mu  ]   [     2]

# 
# The solutions are consistent with the conditions for an interior
# solution.  So, the profit maximising prices are:
# 
> p[1]:=subs(q[1]=500000,p[1]);

                              p[1] := 17

> p[2]:=subs(q[2]=500000,p[2]);

                              p[2] := 13

# 
# c)
# 
> restart;
# 
# Note that lambda>mu in the above solution.  This implies that as the
# cost of capacity is reduced the capacity constraint will cease to be
# binding for off-peak periods before it becomes non-binding for peak
# periods.  So, a useful way to proceed would be to determine whether at
# the reduced capacity cost of $0.03, the capacity constraint has become
# non-binding for the off-peak period (q[2]).  
# 
# Reset the model:
# 
> p[1]:=22-10^(-5)*q[1]:
> p[2]:=18-10^(-5)*q[2]:
> Q:=q[1]+q[2]:
> L:=p[1]*q[1]+p[2]*q[2]-3*k-6*Q+lambda*(k-q[1])+mu*(k-q[2]);
# 

L := (22 - 1/100000 q[1]) q[1] + (18 - 1/100000 q[2]) q[2] - 3 k

     - 6 q[1] - 6 q[2] + lambda (k - q[1]) + mu (k - q[2])

# 
# The appropriate Kuhn-Tucker conditions are as in (b) for all but the
# last two conditions. 
#  They are now:  (lambda>0, q[1]=k) and (mu=0,q[2]<k):
# 
# Now we proceed as in (b):
# 
> with(linalg):
> a:=jacobian([diff(L,q[1]),diff(L,q[2]),diff(L,k),mu],[q[1],q[2],lambda
> ,mu]);
Warning, new definition for norm
Warning, new definition for trace

                       [ -1                       ]
                       [-----      0      -1     0]
                       [50000                     ]
                       [                          ]
                       [          -1              ]
                  a := [  0      -----     0    -1]
                       [         50000            ]
                       [                          ]
                       [  0        0       1     1]
                       [                          ]
                       [  0        0       0     1]

> b:=matrix(4,1,[-16,-12,3,0]);

                                   [-16]
                                   [   ]
                                   [-12]
                              b := [   ]
                                   [  3]
                                   [   ]
                                   [  0]

> matrix(4,1,[q[1],q[2],lambda,mu])=linsolve(a,b);

                         [ q[1] ]   [650000]
                         [      ]   [      ]
                         [ q[2] ]   [600000]
                         [      ] = [      ]
                         [lambda]   [     3]
                         [      ]   [      ]
                         [  mu  ]   [     0]

# Again, the solutions are consistent with the Kuhn-Tucker conditions,
# so at the lower capacity cost there is excess capacity for off-peak
# periods.  The proift mamimizing prices are:
# 
> p[1]:=subs(q[1]=650000,p[1]);

                             p[1] := 31/2

> p[2]:=subs(q[2]=600000,p[2]);

                              p[2] := 12

> 
# 
# 
# 
